%%%-------------------------------------------------------------------
%%% @author admin
%%% @copyright (C) 2022, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 07. 六月 2022 18:38
%%%-------------------------------------------------------------------
-module(player_sl).
-author("admin").

-include("player.hrl").

%% API
-export([
    save/1,
    load/1,
    feilds/0
]).


save(#player{
    uuid = UUid,
    name = Name
}) ->
    Data =
        [
            <<"uuid">>,    UUid
            ,<<"name">>,    Name
        ],
    {ok, Data};
save(_) ->
    {error, bad_record}.


load(Data) ->
    load(Data, #player{}).
load([], Player) -> {ok, Player};
load([{<<"uuid">>, UUid}|Data], Player = #player{}) ->
    load(Data, Player#player{uuid = UUid});
load([{<<"name">>, Val}|Data], Player = #player{}) ->
    load(Data, Player#player{name = Val});
load([_ | Data], Player) ->
    load(Data, Player).

feilds() ->
    [uuid, name].